package com.wx.mall.operate.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wx.mall.common.vo.goods.SpuVo;
import com.wx.mall.feign.GoodListFeignClient;
import com.wx.mall.operate.dto.DisSpuDto;
import com.wx.mall.operate.entity.DisSpu;
import com.wx.mall.operate.mapper.DisSpuMapper;
import com.wx.mall.operate.service.IDisSpuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 优惠券spu关联表 服务实现类
 * </p>
 *
 * @author j
 * @since 2020-05-13
 */
@Service
public class DisSpuServiceImpl extends ServiceImpl<DisSpuMapper, DisSpu> implements IDisSpuService {

    @Resource
    private GoodListFeignClient client;

    @Override
    public void addOne(DisSpuDto disSpuDto) {
        if(disSpuDto.getIds()==null||disSpuDto.getIds().size()==0){

            List<SpuVo> list=client.getList();

            for (SpuVo sp : list
            ) {

                DisSpu spu=new DisSpu();
                spu.setDisId(disSpuDto.getDisId());
                spu.setSpuId(sp.getId());
                this.save(spu);

            }

        }else {

            for (Integer spuId : disSpuDto.getIds()
                 ) {
                DisSpu spu=new DisSpu();
                spu.setDisId(disSpuDto.getDisId());
                spu.setSpuId(spuId);
               this.save(spu);

            }

        }

    }
}
